package chapter08_class

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test12_Extends
 * Package: chapter08_class
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-07-03
 *          Time: 15:53
 */

//检查类型 和 转换
object Test12_Extends {
  def main(args: Array[String]): Unit = {
    //1.类型的检测和转换
    val student = new Student12("alice",20)
    student.study()
    student.say

    //父类引用引用子类对象 多态 动态绑定
    val person12:Person12 = new Student12("bob",20)
    person12.say

    println(student.isInstanceOf[Student12])
    println(student.isInstanceOf[Person12])
    println(person12.isInstanceOf[Person12])
    println(person12.isInstanceOf[Student12]) //也是true
    //如果判断不出来 怎么能形成多态呢
    //但是父类对象 不能判断为子类类型

    val person:Person12 = new Person12("alic",20)
    println(person.isInstanceOf[Student12]) //[类名]
    //但是父类对象 不能判断为子类类型

    //2.测试枚举对象
    println(WorkDay.MONDAY) //Monday

    //定义应用类


  }
}

object TestApp extends App{
  println("app start")
}



//定义枚举类对象
object WorkDay extends Enumeration{
  val MONDAY = Value(1,"Monday")
  val TUESDAY = Value(2,"TuesDay")
}




class Person12(val name:String,val age:Int) {
  def say={
    println("hi from person " + name)
  }
}


class Student12(name:String,age:Int) extends Person12(name,age){
  override def say: Unit = {
    println("hi form student " + name)
  }

  def study()={
    println("student study")
  }

}